I have created an Object in MongoDB.
{
_id : new ObjectId("62181c392c33d3fc59f55ddc"),
name: Escalade,
Brand: Cadillac
}
I want to log the object without ObjectId in the _id
{
_id : "62181c392c33d3fc59f55ddc";
name: Escalade,
Brand: Cadillac
}
How to do it?
When you add a value in mongodb, in a mongo db collection, it automatically makes a field name _id that is used as a primary key.
Think of it this way. This is how mongo knows the difference between an entry and an other entry
ex:
{
_id : "62181c392c33d3fc59f55ddc";
name: Escalade,
Brand: Cadillac
}
{
_id : "62181c392c33d3fc59f55ddf";
name: Escalade,
Brand: Cadillac
}
The first Escalade (for mongo) is different from the second Escalade
The only way to get rid of this "_id", is to declare it, when you make the entry.
For example make an entry like this:
{
_id : "1";
name: some_name,
Brand: some_brand
}
The new entry will have your own _id and mongo will know that "some_name" has the _id of 1
You can search furthermore here: https://docs.mongodb.com/manual/core/document/
Specifically, when you leave this field ("_id") empty, mongo just inputs an object Id variable. So, you cannot remove it, just declare the "_id" as a string or an integer, basically anything but not an array